#include "arch/mips/MIPSProcessorState.h"

using namespace crossbit;

void MIPSProcessorState::dumpToFile( XTFile fd )
{
		SYSCALL::XTWrite(fd, (void*)regs, sizeof(XTInt32)*34);	
		SYSCALL::XTWrite(fd, (void*)fp_regs, sizeof(XTInt32)*34);
}

void MIPSProcessorState::loadFromFile( XTFile fd )
{
		SYSCALL::XTRead(fd, (void*)regs, sizeof(XTInt32)*34);	
		SYSCALL::XTRead(fd, (void*)fp_regs, sizeof(XTInt32)*34);
}

// Dump the register file
void MIPSProcessorState::dump()
{
		std::cout << "MIPS Register File Dump: " << std::endl
				<< "\t$zero 0x"<< std::hex << *(XTUint32*)&regs[$zero]<<std::endl
				<< "\t$at: 0x" << std::hex << *(XTUint32*)&regs[$at] << std::endl
				<< "\t$v0: 0x" << std::hex <<  *(XTUint32 *)&regs[$v0] << std::endl
				<< "\t$v1: 0x" << std::hex << *(XTUint32 *)&regs[$v1] <<  std::endl
				<< "\t$a0: 0x" << std::hex << *(XTUint32 *)&regs[$a0] <<  std::endl
				<< "\t$a1: 0x" << std::hex << *(XTUint32 *)&regs[$a1] <<  std::endl 
				<< "\t$a2: 0x" << std::hex << *(XTUint32 *)&regs[$a2] <<  std::endl
				<< "\t$a3: 0x" << std::hex << *(XTUint32 *)&regs[$a3] <<  std::endl
				<< "\t$t0: 0x" << std::hex << *(XTUint32 *)&regs[$t0] <<  std::endl
				<< "\t$t1: 0x" << std::hex << *(XTUint32 *)&regs[$t1] <<  std::endl
				<< "\t$t2: 0x" << std::hex << *(XTUint32 *)&regs[$t2] <<  std::endl
				<< "\t$t3: 0x" << std::hex << *(XTUint32 *)&regs[$t3] <<  std::endl
				<< "\t$t4: 0x" << std::hex << *(XTUint32 *)&regs[$t4] <<  std::endl
				<< "\t$t5: 0x" << std::hex << *(XTUint32 *)&regs[$t5] <<  std::endl
				<< "\t$t6: 0x" << std::hex << *(XTUint32 *)&regs[$t6] <<  std::endl
				<< "\t$t7: 0x" << std::hex << *(XTUint32 *)&regs[$t7] <<  std::endl
				<< "\t$s0: 0x" << std::hex << *(XTUint32 *)&regs[$s0] <<  std::endl
				<< "\t$s1: 0x" << std::hex << *(XTUint32 *)&regs[$s1] <<  std::endl
				<< "\t$s2: 0x" << std::hex << *(XTUint32 *)&regs[$s2] <<  std::endl
				<< "\t$s3: 0x" << std::hex << *(XTUint32 *)&regs[$s3] <<  std::endl
				<< "\t$s4: 0x" << std::hex << *(XTUint32 *)&regs[$s4] <<  std::endl
				<< "\t$s5: 0x" << std::hex << *(XTUint32 *)&regs[$s5] <<  std::endl
				<< "\t$s6: 0x" << std::hex << *(XTUint32 *)&regs[$s6] <<  std::endl
				<< "\t$s7: 0x" << std::hex << *(XTUint32 *)&regs[$s7] <<  std::endl
				<< "\t$t8: 0x" << std::hex << *(XTUint32 *)&regs[$t8] <<  std::endl
				<< "\t$t9: 0x" << std::hex << *(XTUint32 *)&regs[$t9] <<  std::endl
				<< "\t$k0: 0x" << std::hex << *(XTUint32 *)&regs[$k0] <<  std::endl
				<< "\t$k1: 0x" << std::hex << *(XTUint32 *)&regs[$k1] <<  std::endl
				<< "\t$gp: 0x" << std::hex << *(XTUint32 *)&regs[$gp] <<  std::endl
				<< "\t$sp: 0x" << std::hex << *(XTUint32 *)&regs[$sp] <<  std::endl
				<< "\t$s8: 0x" << std::hex << *(XTUint32 *)&regs[$s8] <<  std::endl
				<< "\t$ra: 0x" << std::hex << *(XTUint32 *)&regs[$ra] <<  std::endl
				<< "\t$hi: 0x" << std::hex << *(XTUint32 *)&regs[$hi] <<  std::endl
				<< "\t$lo: 0x" << std::hex << *(XTUint32 *)&regs[$lo] <<  std::endl
				<< "PISA Float Point Register Dump:" << std::endl;
		int i;
		for ( i = 0; i < 34; i++)
				std::cout << "\t$f" <<(XTInt32)i<< ": 0x"
						<< std::hex << fp_regs[i] 
						<< std::endl;
}


